package com.woniu.adopt_web.config;

import com.woniu.adopt_web.filter.LoginFilter;
import com.woniu.adopt_web.interceptor.LoginInterceptor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.Filter;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/petArticle.html").setViewName("petArticle");
        registry.addViewController("/petAdopt.html").setViewName("petAdopt");
        registry.addViewController("/activity.html").setViewName("activity");
//        registry.addViewController("/comment.html").setViewName("comment");
        registry.addViewController("/team.html").setViewName("team");
        registry.addViewController("/personal.html").setViewName("personal");


    }
    @Bean
    public FilterRegistrationBean<Filter> filterFilterRegistrationBean(){
        FilterRegistrationBean<Filter> filter = new FilterRegistrationBean<>(new LoginFilter());
        filter.addUrlPatterns("/login.html");
        return filter;
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/personal.html")
                .addPathPatterns("/user/showPetColList")
                .addPathPatterns("/user/myMessage")
                .excludePathPatterns("/user/modify")
                .excludePathPatterns("/oss/upload");//拦截个人中心
    }
}
